
#pragma once

#include <core.h>
#include <GameHelper.h>
#include<map>
using namespace std;

class CSkelMeshNode;
class CRigidMeshNode;
class _Bone;
class _Anim;
class _BoneNode;
class _ModelRCDes;

class SMeshContainer;
class _BONELIST;
class ANILIST;
class _BONEBIN;
class SDrawElement;
class MESHINFO;
class BONEINFO;
class AddOnContainer;
class ANIATTR_VER2;

typedef map<BYTE,BYTE> MapBonID;//old id,new id
class CModelStructTransf
{

public:
	static CModelStructTransf& GetSingleton()
	{
		static CModelStructTransf m_Instance;
		return m_Instance;
	}

	void TransfAndSaveSkelMesh(const SMeshContainer* pOld,const MESHINFO* pInfor);
	void TransfAndSaveBone(const _BONELIST* pOld,const BONEINFO* pInfor);
	void TransfAndSaveAnim(const ANILIST* pOld,const MESHINFO* pInfor,const int& iIndexEx = 0);	//NPC type used iIndexEx

	//eRCType = RC_NPCWEAPON or RC_ITEM, MESHINFO only set pInfor->class
	void TransfAndSaveRigidMesh(const AddOnContainer* pOld,const MESHINFO* pInfor,const int& eRCType);	

private:
	_Bone*          BoneTransf(const _BONELIST* pOld);
	CSkelMeshNode*  SkelMeshTransf(const SMeshContainer* pOld,const _ModelRCDes* pDes);
	_Anim*          AnimTransf(const ANILIST* pOld,const _ModelRCDes* pDes);
	
	CRigidMeshNode* RigidMeshTransf(const AddOnContainer* pOld,const _ModelRCDes* pDes);

	void SaveSkelMesh(const _ModelRCDes* pDes,CSkelMeshNode* pMesh);
	void SaveBone(const _ModelRCDes* pDes,_Bone* pBone);
	void SaveAnim(const _ModelRCDes* pDes,_Anim* pAnim);
	void SaveRigidMesh(const _ModelRCDes* pDes,CRigidMeshNode* pMesh,const int& eRCType);

	void _BONEBIN2_BoneNode(_BoneNode* pNew,const _BONEBIN* pOld,const _Bone* pNewBone);
	BOOL BoneIDTransfer(_BoneNode* pNewNode,_BONELIST* pOldBoneList,MapBonID& mapBonID);
	BOOL BoneMapIDInit(const _ModelRCDes* pDes,MapBonID& mapBoneID);

	void AddAniEvent( const ANIATTR_VER2& attr, _Anim* pNew );
	int ConvertEventType( int oldEventType, bool isStart );
	inline int FilterData( int oldIndex )
	{
		int index = 0;
		if ( oldIndex != -1 )
			index = oldIndex;
		return index;
	}
};
